package com.sc.thread.volatiletest;

/**
 * Created by Shen Chao on 2018-07-03-003.
 */
public class VolatileTest {
    private volatile int num = 0;

    private void increase() {
        num++;
    }

    public static void main(String[] args) {
        final VolatileTest test = new VolatileTest();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 10; j++) {
                    test.increase();
                }
            }).start();
        }

        while (Thread.activeCount() > 1) { //保证前面的线程都执行完
            Thread.yield();
        }
        System.out.println(test.num);
    }
}
